package com.css.fxfzysx.modules.lifeline.repository.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzysx.modules.cztDataMange.entity.RdInformationEntity;
import com.css.fxfzysx.modules.lifeline.entity.*;
import com.css.fxfzysx.modules.lifeline.entity.newEntity.SmxRoadEntity;
import com.css.fxfzysx.modules.lifeline.entity.newEntity.SmxVersionEntity;
import com.css.fxfzysx.modules.lifeline.param.RegionParam;
import com.css.fxfzysx.modules.lifeline.repository.LifelineRepository;
import com.css.fxfzysx.modules.lifeline.vo.QueryParamsVo;
import com.css.fxfzysx.util.PlatformObjectUtils;
import com.css.fxfzysx.web.PlatformSessionContext;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class LifelineRepositoryImpl implements LifelineRepository {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;


    @Override
    public boolean saveDxPipeNetwork(DxPipeNetworkEntity dxPipeNetworkEntity) {
        String sql = "insert into czt_dx_pipe_network values (:cdpnId,:id,:attachId,:cdpnName,:cdpnClass,:startId,:endId,:longitude,:latitude,:length,:material,:materialType,:elasticModulus,:yieldLimitStress,:strengthLimitStress,:permissibleStrain,:diameter,:thickness,:pressure,:joint,:jointy,:allowableElongation,:site,:liquefaction6,:liquefaction7,:liquefaction8,:liquefaction9,:seismicSubsidence6,:seismicSubsidence7,:seismicSubsidence8,:seismicSubsidence9,:depth,:year,:intensity,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county," +
                "ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(dxPipeNetworkEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveLifelineAttachmentRecord(LifelineAttachmentRecordEntity lifelineAttachmentRecord) {
        String sql = "insert into czt_lifeline_attachment_record(id, attach_id, attach_name, attach_path, local_dir, type, file_type, create_user, create_time, del_flag) " +
                "values(:id, :attachId, :attachName, :attachPath, :localDir, :type, :fileType, :createUser, :createTime, :delFlag)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(lifelineAttachmentRecord);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveWaterWork(WaterWorksEntity waterWorksEntity) {
        String sql = "insert into czt_waterworks values(:cwId,:cwName,:longitude,:latitude,:id,:buildingName,:type,:floors,:area,:material,:materialType,:site,:liquefaction6,:liquefaction7,:liquefaction8,:liquefaction9,:seismicSubsidence6,:seismicSubsidence7,:seismicSubsidence8,:seismicSubsidence9,:year,:intensity,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county,ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:attachId)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(waterWorksEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean savePool(PoolEntity poolEntity) {
        String sql = "insert into czt_pool values(:cpId,:id,:style,:material,:thickness,:shape,:radius,:slength,:length,:capacity,:depth,:height,:joint,:present,:quality,:surfaceShape1,:surfaceShape2,:diameter1,:diameter2,:strengthGrade,:kinds1,:kinds2,:thicknessLayer1,:thicknessLayer2,:innerReinforcement,:outReinforcement,:intensity,:site,:year,:liquefaction6,:liquefaction7,:liquefaction8,:liquefaction9,:landform6,:landform7,:landform8,:landform9,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county,ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:attachId,:longitude,:latitude)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(poolEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveAirReceiver(AirReceiverEntity airReceiverEntity) {
        String sql = "insert into czt_air_receiver values(:carId,:id,:carName,:longitude,:latitude,:style,:capacity,:pressure,:innerDiameter,:height,:thickness,:weight,:material,:railLength,:railHeight,:railThickness,:baseType,:materialType,:elasticModulus,:yieldStress,:permissibleStress,:site,:liquefaction6,:liquefaction7,:liquefaction8,:liquefaction9,:seismicSubsidence6,:seismicSubsidence7,:seismicSubsidence8,:seismicSubsidence9,:year,:intensity,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,ST_GeometryFromText(:geom,4490),:attachId,:province,:city,:county)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(airReceiverEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveBridgePoint(BridgeEntity bridgeEntity) {
        String sql = "insert into czt_bridge_point values(:cbId,:id,:cbName,:location,:acrossObject,:intensity,:buildYear,:structure,:maxSpan,:length,:siteSoil,:grade,:foundationFail,:superStructure,:bearing,:pierHeight,:pierMaterial,:basement,:capacity,:abutmentMat,:abutmentType,:expansionJoint,:width,:note,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county,ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:longitude,:latitude,:attachId,:flag)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(bridgeEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveBridgeLine(BridgeEntity bridgeEntity) {
        String sql = "insert into czt_bridge_line values(:cbId,:id,:cbName,:location,:acrossObject,:intensity,:buildYear,:structure,:maxSpan,:length,:siteSoil,:grade,:foundationFail,:superStructure,:bearing,:pierHeight,:pierMaterial,:basement,:capacity,:abutmentMat,:abutmentType,:expansionJoint,:width,:note,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county,ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:longitude,:latitude,:attachId,:flag)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(bridgeEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveRoad(SmxRoadEntity entity) {
/*        return jdbcTemplate.update("insert into czt_smx_road  (id,road_id,name,grade,intensity,roadbed_soil,site_soil,fortification,foundation_fail,roadbed_type,roadbed_high,year,province,city,county,capacity,pavement,length,width,note,create_user,create_user_name,create_time,del_flag,org_name,destructive_state,destructive_state_correct,ub_ind,oi,p02,p24,p46,p68,p810,basic_intact,slight_damage,moderate_damage,badly_damaged,destroy,basic_intact_correct,slight_damage_correct,moderate_damage_correct,badly_damaged_correct,destroy_correct,start_longitude,start_latitude,end_longitude,end_latitude) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
               entity.getId(),entity.getRoadId(),entity.getName(),entity.getGrade(),entity.getIntensity(),entity.getRoadbedSoil(),entity.getSiteSoil(),entity.getFortification(),entity.getFoundationFail(),entity.getRoadbedType(),entity.getRoadbedHigh(),entity.getYear(),entity.getProvince(),entity.getCity(),entity.getCounty(),entity.getCapacity(),entity.getPavement(),entity.getLength(),entity.getWidth(),entity.getNote(),entity.getCreateUser(),entity.getCreateUserName(),entity.getCreateTime(),entity.getDelFlag(),entity.getOrgName(),entity.getDestructiveState(),entity.getDestructiveStateCorrect(),entity.getUbInd(),entity.getOi(),entity.getP02(),entity.getP24(),entity.getP46(),entity.getP68(),entity.getP810(),entity.getBasicIntact(),entity.getSlightDamage(),entity.getModerateDamage(),entity.getBadlyDamaged(),entity.getDestroy(),entity.getBasicIntactCorrect(),entity.getSlightDamageCorrect(),entity.getModerateDamageCorrect(),entity.getBadlyDamagedCorrect(),entity.getDestroyCorrect(),entity.getStartLongitude(),entity.getStartLatitude(),entity.getEndLongitude(),entity.getEndLatitude())>0;*/
        String sql = "insert into czt_smx_road values(:id,:roadId,:name,:grade,:intensity,:roadbedSoil,:siteSoil,:fortification,:foundationFail,:roadbedType,:roadbedHigh,:year,:province,:city,:county,:capacity,:pavement,:length,:width,:note,:createUser,:createUserName,:createTime,:updateUser,:updateTime,:delFlag,:orgName,:destructiveState,:destructiveStateCorrect,:ubInd,:oi,:p02,:p24,:p46,:p68,:p810,:basicIntact,:slightDamage,:moderateDamage,:badlyDamaged,:destroy,:basicIntactCorrect,:slightDamageCorrect,:moderateDamageCorrect,:badlyDamagedCorrect,:destroyCorrect,:startLongitude,:startLatitude,:endLongitude,:endLatitude,ST_GeometryFromText(:geom,4490),:version_id)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(entity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveTransformerSubstation(TransformerSubstationEntity transformerSubstationEntity) {
        String sql = "insert into czt_transformer_substation values(:ctsId,:id,:ctsName,:position,:longitude,:latitude,:typeSubstation,:voltageGrade,:structureType,:fortificationIntensity,:substationTotalCost,:costHighVoltageOutdoor,:costIndoorEquipment,:costBuilding,:year,:site,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county,ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:attachId)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(transformerSubstationEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveOverheadLine(OverheadLineEntity overheadLineEntity) {
        String sql = "insert into czt_overhead_line values(:colId,:id,:colName,:fortificationIntensity,:voltageGrade35,:lineLength35,:loopLength35,:landform35,:unitCostLine35,:type35,:number35,:unitCostTower35,:voltageGrade66,:lineLength66,:loopLength66,:landform66,:unitCostLine66,:type66,:number66,:unitCostTower66,:voltageGrade110,:lineLength110,:loopLength110,:landform110,:unitCostLine110,:type110,:number110,:unitCostTower110,:voltageGrade220,:lineLength220,:loopLength220,:landform220,:unitCostLine220,:type220,:number220,:unitCostTower220,:voltageGrade330,:lineLength330,:loopLength330,:landform330,:unitCostLine330,:type330,:number330,:unitCostTower330,:voltageGrade500,:lineLength500,:loopLength500,:landform500,:unitCostLine500,:type500,:number500,:unitCostTower500,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county,ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:attachId)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(overheadLineEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveCableRoute(CableRouteEntity cableRouteEntity) {
        String sql = "insert into czt_cable_route values(:ccrId,:id,:ccrName,:fortificationIntensity,:lineLength,:costLine,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county,ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:attachId)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(cableRouteEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveImportantPowerhouse(ImportantPowerhouseEntity importantPowerhouseEntity) {
        String sql = "insert into czt_important_powerhouse values(:cipId,:id,:cipName,:position,:longitude,:latitude,:year,:fortificationIntensity,:installedCapacity,:generatingType,:costPowerPlant,:costSubstationEquipment,:costGeneratingEquipment,:areaSteelStructures,:unitCostSteelStructure,:areaReinforcedConcrete,:unitCostReinforcedConcrete,:areaMasonryStructure,:unitCostmasonryStructure,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county,ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:attachId)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(importantPowerhouseEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveCommIndoorEquipment(CommIndoorEquipmentEntity commIndoorEquipment) {
        String sql = "insert into czt_comm_indoor_equipment values(:ccieId,:inObjectName,:location,:objectLon,:objectLat,:deviceType,:deviceName,:model,:inFloor,:fixedForm,:boltDiameter,:purchaseCost,:manufacturers,:size,:weight,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county,ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:attachId)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(commIndoorEquipment);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean saveTvTower(TvTowerEntity tvTowerEntity) {
        String sql = "insert into czt_tv_tower values(:cttId,:objectName,:location,:objectLon,:objectLat,:cttType,:area,:year,:height,:towerElevation,:buldingSite,:designIntensity,:fieldType,:status,:reconstructionCost,:antennaElevation,:period,:colmnType,:baseType,:baseStoryNum,:baseHeight,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:province,:city,:county,ST_GeometryFromText(:geom,4490),:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:attachId)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(tvTowerEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public Map<String, Object> page(QueryParamsVo queryParams, int curPage, int pageSize) {
        String type = queryParams.getType();
        StringBuilder sql = new StringBuilder("select * from ");
        //type 1:地下管网   2:水厂泵房  3:水厂水池  4:燃气-储气罐    5:桥梁    6:道路    7:变电站
        // 8:架空线路  9:电缆线路  10:发电厂  11:通信室内设备   12:电视塔
        if(type.equals("1")){
            sql.append(" czt_dx_pipe_network ");
        }else if(type.equals("2")){
            sql.append(" czt_waterworks ");
        }else if(type.equals("3")){
            sql.append(" czt_pool ");
        }else if(type.equals("4")){
            sql.append(" czt_air_receiver ");
        }else if(type.equals("6")){
            sql.append(" czt_road ");
        }else if(type.equals("7")){
            sql.append(" czt_transformer_substation ");
        }else if(type.equals("8")){
            sql.append(" czt_overhead_line ");
        }else if(type.equals("9")){
            sql.append(" czt_cable_route ");
        }else if(type.equals("10")){
            sql.append(" czt_important_powerhouse ");
        }else if(type.equals("11")){
            sql.append(" czt_comm_indoor_equipment ");
        }else if(type.equals("12")){
            sql.append(" czt_tv_tower ");
        }else if(type.equals("13")){
            sql.append(" czt_major_project ");
        }else if(type.equals("14")){
            sql.append(" czt_reservior ");
        }
        Map<String,Object> map = new HashMap();
        StringBuilder whereSql = new StringBuilder();
        StringBuilder orderSql = new StringBuilder();
        StringBuilder limitSql = new StringBuilder();
        if(!type.equals("5")){//不为桥梁时
            whereSql.append(" where del_flag= '0' ");
            if(!PlatformObjectUtils.isEmpty(queryParams.getProvince())){
                whereSql.append(" and province = '"+ queryParams.getProvince()+"'");
            }
            if(!PlatformObjectUtils.isEmpty(queryParams.getCity())){
                whereSql.append(" and city = '"+ queryParams.getCity()+"'");
            }
            if(!PlatformObjectUtils.isEmpty(queryParams.getCounty())){
                whereSql.append(" and county = '"+ queryParams.getCounty()+"'");
            }
            orderSql.append(" order by create_time,update_time desc ");
            limitSql.append(" limit "+pageSize+" offset "+ (curPage-1) * pageSize);
            Integer total = jdbcTemplate.query(sql.append(whereSql).toString(), new BeanPropertyRowMapper<>(Object.class)).size();
            map.put("total",total);
        }

        if(type.equals("1")){
            List<DxPipeNetworkEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(DxPipeNetworkEntity.class));
            map.put("rows",list);
        }else if(type.equals("2")){
            List<WaterWorksEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(WaterWorksEntity.class));
            map.put("rows",list);
        }else if(type.equals("3")){
            List<PoolEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(PoolEntity.class));
            map.put("rows",list);
        }else if(type.equals("4")){
            List<AirReceiverEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(AirReceiverEntity.class));
            map.put("rows",list);
        }else if(type.equals("6")){
            List<RoadEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(RoadEntity.class));
            map.put("rows",list);
        }else if(type.equals("7")){
            List<TransformerSubstationEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(TransformerSubstationEntity.class));
            map.put("rows",list);
        }else if(type.equals("8")){
            List<OverheadLineEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(OverheadLineEntity.class));
            map.put("rows",list);
        }else if(type.equals("9")){
            List<CableRouteEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(CableRouteEntity.class));
            map.put("rows",list);
        }else if(type.equals("10")){
            List<ImportantPowerhouseEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(ImportantPowerhouseEntity.class));
            map.put("rows",list);
        }else if(type.equals("11")){
            List<CommIndoorEquipmentEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(CommIndoorEquipmentEntity.class));
            map.put("rows",list);
        }else if(type.equals("12")){
            List<TvTowerEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(TvTowerEntity.class));
            map.put("rows",list);
        }else if(type.equals("13")){
            List<MajorProjectEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(MajorProjectEntity.class));
            map.put("rows",list);
        }else if(type.equals("14")){
            List<RdInformationEntity> list = jdbcTemplate.query(sql.append(orderSql).append(limitSql).toString(), new BeanPropertyRowMapper<>(RdInformationEntity.class));
            map.put("rows",list);
        }
        //桥梁
        //一个实体类对应两个表单,实体类为BridgeEntity,表单名字分别是czt_bridge_point和czt_bridge_line,
        // 两个表中的字段完全相同,同时查询两个表的数据,1.获得总条数,2.根据条件 省(province) 市(city) 区/县(county) 进行条件查询,根据创建时间排序,并分页,获取最终的结果集
        if(type.equals("5")){
            StringBuilder pointSql = new StringBuilder("select * from czt_bridge_point ");//union
            StringBuilder lineSql = new StringBuilder(" union select * from czt_bridge_line ");
            StringBuilder pointWhereSql = new StringBuilder(" where del_flag = '0'");
            StringBuilder lineWhereSql = new StringBuilder(" where del_flag = '0'");
            StringBuilder bridgeOrderSql = new StringBuilder("  order by create_time ");
            if(!PlatformObjectUtils.isEmpty(queryParams.getProvince())){
                pointWhereSql.append(" and province = '"+ queryParams.getProvince()+"'");
                lineWhereSql.append(" and province = '"+ queryParams.getProvince()+"'");
            }
            if(!PlatformObjectUtils.isEmpty(queryParams.getCity())){
                pointWhereSql.append(" and city = '"+ queryParams.getCity()+"'");
                lineWhereSql.append(" and city = '"+ queryParams.getCity()+"'");
            }
            if(!PlatformObjectUtils.isEmpty(queryParams.getCounty())){
                pointWhereSql.append(" and county = '"+ queryParams.getCounty()+"'");
                lineWhereSql.append(" and county = '"+ queryParams.getCounty()+"'");
            }
            String bridgeSql = pointSql.append(pointWhereSql).append(lineSql).append(lineWhereSql).append(bridgeOrderSql).toString();
            Integer total = jdbcTemplate.query(bridgeSql, new BeanPropertyRowMapper<>(Object.class)).size();
            map.put("total",total);
            StringBuilder bridgeLimitSql = new StringBuilder(" limit "+pageSize+" offset "+ (curPage-1) * pageSize);
            List<BridgeEntity> list = jdbcTemplate.query(bridgeSql + bridgeLimitSql.toString(), new BeanPropertyRowMapper<>(BridgeEntity.class));
            map.put("rows",list);
        }
        return map;
    }

    @Override
    public Map findById(String id, String type) {
        StringBuilder sql = new StringBuilder("select * from ");
        //type 1:地下管网   2:水厂泵房  3:水厂水池  4:燃气-储气罐    5:桥梁    6:道路    7:变电站
        // 8:架空线路  9:电缆线路  10:发电厂  11:通信室内设备   12:电视塔
        if(type.equals("1")){
            sql.append(" czt_dx_pipe_network where del_flag= '0' and cdpn_id = ?");
        }else if(type.equals("2")){
            sql.append(" czt_waterworks where del_flag= '0' and cw_id = ?");
        }else if(type.equals("3")){
            sql.append(" czt_pool where del_flag= '0' and cp_id = ?");
        }else if(type.equals("4")){
            sql.append(" czt_air_receiver where del_flag= '0' and car_id = ?");
        }else if(type.equals("6")){
            sql.append(" czt_road  where del_flag= '0' and cr_id = ? ");
        }else if(type.equals("7")){
            sql.append(" czt_transformer_substation  where del_flag= '0' and cts_id = ? ");
        }else if(type.equals("8")){
            sql.append(" czt_overhead_line  where del_flag= '0' and col_id = ? ");
        }else if(type.equals("9")){
            sql.append(" czt_cable_route  where del_flag= '0' and car_id = ? ");
        }else if(type.equals("10")){
            sql.append(" czt_important_powerhouse  where del_flag= '0' and cip_id = ? ");
        }else if(type.equals("11")){
            sql.append(" czt_comm_indoor_equipment  where del_flag= '0' and ccie_id = ? ");
        }else if(type.equals("12")){
            sql.append(" czt_tv_tower where del_flag= '0' and ctt_id = ? ");
        }else if(type.equals("13")){
            sql.append(" czt_major_project where del_flag= '0' and cmp_id = ? ");
        }else if(type.equals("14")){
            sql.append(" czt_reservior where del_flag= '0' and cmp_id = ? ");
        }
        try {
            Map<String,Object> map=new HashMap();
            if(type.equals("1")){
                DxPipeNetworkEntity dxPipeNetworkEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(DxPipeNetworkEntity.class),id);
                map.put("data",dxPipeNetworkEntity);
            }else if(type.equals("2")){
                WaterWorksEntity waterWorksEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(WaterWorksEntity.class),id);
                map.put("data",waterWorksEntity);
            }else if(type.equals("3")){
                PoolEntity poolEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(PoolEntity.class),id);
                map.put("data",poolEntity);
            }else if(type.equals("4")){
                AirReceiverEntity airReceiverEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(AirReceiverEntity.class),id);
                map.put("data",airReceiverEntity);
            }else if(type.equals("6")){
                RoadEntity roadEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(RoadEntity.class),id);
                map.put("data",roadEntity);
            }else if(type.equals("7")){
                TransformerSubstationEntity transformerSubstationEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(TransformerSubstationEntity.class),id);
                map.put("data",transformerSubstationEntity);
                return map;
            }else if(type.equals("8")){
                OverheadLineEntity overheadLineEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(OverheadLineEntity.class),id);
                map.put("data",overheadLineEntity);
            }else if(type.equals("9")){
                CableRouteEntity cableRouteEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(CableRouteEntity.class),id);
                map.put("data",cableRouteEntity);
            }else if(type.equals("10")){
                ImportantPowerhouseEntity importantPowerhouseEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(ImportantPowerhouseEntity.class),id);
                map.put("data",importantPowerhouseEntity);
            }else if(type.equals("11")){
                CommIndoorEquipmentEntity commIndoorEquipmentEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(CommIndoorEquipmentEntity.class),id);
                map.put("data",commIndoorEquipmentEntity);
            }else if(type.equals("12")){
                TvTowerEntity tvTowerEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(TvTowerEntity.class),id);
                map.put("data",tvTowerEntity);
            }else if(type.equals("13")){
                MajorProjectEntity majorProjectEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(MajorProjectEntity.class),id);
                map.put("data",majorProjectEntity);
            }else if(type.equals("14")){
                RdInformationEntity rdInformationEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(RdInformationEntity.class),id);
                map.put("data",rdInformationEntity);
            }
            return map;
        }catch (EmptyResultDataAccessException e){
            return null;
        }
    }

    @Override
    public Boolean update(Map<String, Object> map) {
        //type 1:地下管网   2:水厂泵房  3:水厂水池  4:燃气-储气罐    5:桥梁    6:道路    7:变电站
        // 8:架空线路  9:电缆线路  10:发电厂  11:通信室内设备   12:电视塔
        StringBuilder sql = new StringBuilder();
        String userId = PlatformSessionContext.getUserID();
        Map<String, Object> map1 = (Map) map.get("map");
        String type = (String) map.get("type");
        if(type.equals("1")){
            DxPipeNetworkEntity dxPipeNetworkEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), DxPipeNetworkEntity.class);
            dxPipeNetworkEntity.setUpdateUser(userId);
            dxPipeNetworkEntity.setUpdateTime(new Date());
            sql.append("update czt_dx_pipe_network set id=:id,attach_id=:attachId,province=:province,city=:city,county=:county,cdpn_name=:cdpnName,cdpn_class=:cdpnClass,start_id=:startId,end_id=:endId,longitude=:longitude,latitude=:latitude,length=:length,material=:material,material_type=:materialType,elastic_modulus=:elasticModulus,yield_limit_stress=:yieldLimitStress,strength_limit_stress=:strengthLimitStress,permissible_strain=:permissibleStrain,diameter=:diameter,thickness=:thickness,pressure=:pressure,joint=:joint,jointy=:jointy,allowable_elongation=:allowableElongation,site=:site,liquefaction6=:liquefaction6,liquefaction7=:liquefaction7,liquefaction8=:liquefaction8,liquefaction9=:liquefaction9,seismic_subsidence6=:seismicSubsidence6,seismic_subsidence7=:seismicSubsidence7,seismic_subsidence8=:seismicSubsidence8,seismic_subsidence9=:seismicSubsidence9,depth=:depth,year=:year,intensity=:intensity,update_user=:updateUser,update_time=:updateTime,del_flag=:delFlag,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10");
            sql.append(" where cdpn_id = '"+dxPipeNetworkEntity.getCdpnId()+"'");
            SqlParameterSource source = new BeanPropertySqlParameterSource(dxPipeNetworkEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("2")){
            WaterWorksEntity waterWorksEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), WaterWorksEntity.class);
            waterWorksEntity.setUpdateUser(userId);
            waterWorksEntity.setUpdateTime(new Date());
            sql.append("update czt_waterworks set cw_name=:cwName,province=:province,city=:city,county=:county,longitude=:longitude,latitude=:latitude,id=:id,building_name=:buildingName,type=:type,floors=:floors,area=:area,material=:material,material_type=:materialType,site=:site,liquefaction6=:liquefaction6,liquefaction7=:liquefaction7,liquefaction8=:liquefaction8,liquefaction9=:liquefaction9,seismic_subsidence6=:seismicSubsidence6,seismic_subsidence7=:seismicSubsidence7,seismic_subsidence8=:seismicSubsidence8,seismic_subsidence9=:seismicSubsidence9,year=:year,intensity=:intensity,attach_id=:attachId,update_user=:updateUser,update_time=:updateTime,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10");
            sql.append(" where cw_id = '"+waterWorksEntity.getCwId()+"'");
            SqlParameterSource source = new BeanPropertySqlParameterSource(waterWorksEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("3")){
            PoolEntity poolEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), PoolEntity.class);
            poolEntity.setUpdateUser(userId);
            poolEntity.setUpdateTime(new Date());
            sql.append("update czt_pool set id=:id,province=:province,city=:city,county=:county,style=:style,material=:material,thickness=:thickness,shape=:shape,radius=:radius,slength=:slength,length=:length,capacity=:capacity,depth=:depth,height=:height,joint=:joint,present=:present,quality=:quality,surface_shape1=:surfaceShape1,surface_shape2=:surfaceShape2,diameter1=:diameter1,diameter2=:diameter2,strength_grade=:strengthGrade,kinds1=:kinds1,kinds2=:kinds2,thickness_layer1=:thicknessLayer1,thickness_layer2=:thicknessLayer2,inner_reinforcement=:innerReinforcement,out_reinforcement=:outReinforcement,intensity=:intensity,site=:site,year=:year,liquefaction6=:liquefaction6,liquefaction7=:liquefaction7,liquefaction8=:liquefaction8,liquefaction9=:liquefaction9,landform6=:landform6,landform7=:landform7,landform8=:landform8,landform9=:landform9,update_user=:updateUser,update_time=:updateTime,del_flag=:delFlag,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,attach_id=:attachId,longitude=:longitude,latitude=:latitude");
            sql.append(" where cp_id = '"+poolEntity.getCpId()+"'");
            SqlParameterSource source = new BeanPropertySqlParameterSource(poolEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("4")){
            AirReceiverEntity airReceiverEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), AirReceiverEntity.class);
            airReceiverEntity.setUpdateUser(userId);
            airReceiverEntity.setUpdateTime(new Date());
            sql.append("update czt_air_receiver set id=:id,car_name=:carName,province=:province,city=:city,county=:county,longitude=:longitude,latitude=:latitude,style=:style,capacity=:capacity,pressure=:pressure,inner_diameter=:innerDiameter,height=:height,thickness=:thickness,weight=:weight,material=:material,rail_length=:railLength,rail_height=:railHeight,rail_thickness=:railThickness,base_type=:baseType,material_type=:materialType,elastic_modulus=:elasticModulus,yield_stress=:yieldStress,permissible_stress=:permissibleStress,site=:site,liquefaction6=:liquefaction6,liquefaction7=:liquefaction7,liquefaction8=:liquefaction8,liquefaction9=:liquefaction9,seismic_subsidence6=:seismicSubsidence6,seismic_subsidence7=:seismicSubsidence7,seismic_subsidence8=:seismicSubsidence8,seismic_subsidence9=:seismicSubsidence9,year=:year,intensity=:intensity,update_user=:updateUser,update_time=:updateTime,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,attach_id=:attachId");
            sql.append(" where car_id = '"+airReceiverEntity.getCarId()+"'");
            SqlParameterSource source = new BeanPropertySqlParameterSource(airReceiverEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("5")){
            BridgeEntity bridgeEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), BridgeEntity.class);
            bridgeEntity.setUpdateUser(userId);
            bridgeEntity.setUpdateTime(new Date());
            if(bridgeEntity.getFlag().equals("0")){
                sql.append("update czt_bridge_point set id=:id,cb_name=:cbName,province=:province,city=:city,county=:county,location=:location,across_object=:acrossObject,intensity=:intensity,build_year=:buildYear,structure=:structure,max_span=:maxSpan,length=:length,site_soil=:siteSoil,grade=:grade,foundation_fail=:foundationFail,super_structure=:superStructure,bearing=:bearing,pier_height=:pierHeight,pier_material=:pierMaterial,basement=:basement,capacity=:capacity,abutment_mat=:abutmentMat,abutment_type=:abutmentType,expansion_joint=:expansionJoint,width=:width,note=:note,update_user=:updateUser,update_time=:updateTime,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,longitude=:longitude,latitude=:latitude,attach_id=:attachId");
                sql.append(" where cb_id = '"+bridgeEntity.getCbId()+"' ");
            }else{
                sql.append("update czt_bridge_line set id=:id,cb_name=:cbName,province=:province,city=:city,county=:county,location=:location,across_object=:acrossObject,intensity=:intensity,build_year=:buildYear,structure=:structure,max_span=:maxSpan,length=:length,site_soil=:siteSoil,grade=:grade,foundation_fail=:foundationFail,super_structure=:superStructure,bearing=:bearing,pier_height=:pierHeight,pier_material=:pierMaterial,basement=:basement,capacity=:capacity,abutment_mat=:abutmentMat,abutment_type=:abutmentType,expansion_joint=:expansionJoint,width=:width,note=:note,update_user=:updateUser,update_time=:updateTime,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,longitude=:longitude,latitude=:latitude,attach_id=:attachId");
                sql.append(" where cb_id = '"+bridgeEntity.getCbId()+"' ");
            }
            SqlParameterSource source = new BeanPropertySqlParameterSource(bridgeEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("6")){
            RoadEntity roadEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), RoadEntity.class);
            roadEntity.setUpdateUser(userId);
            roadEntity.setUpdateTime(new Date());
            sql.append("update czt_road set id=:id,cr_name=:crName,province=:province,city=:city,county=:county,cr_class=:crClass,cover=:cover,roadbed_soil=:roadbedSoil,site_soil=:siteSoil,fortification=:fortification,foundation_fail=:foundationFail,roadbed_type=:roadbedType,roadbed_high=:roadbedHigh,capacity=:capacity,pavement=:pavement,length=:length,width=:width,note=:note,update_user=:updateUser,update_time=:updateTime,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,attach_id=:attachId");
            sql.append(" where cr_id = '"+roadEntity.getCrId()+"' ");
            SqlParameterSource source = new BeanPropertySqlParameterSource(roadEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("7")){
            TransformerSubstationEntity transformerSubstationEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), TransformerSubstationEntity.class);
            transformerSubstationEntity.setUpdateUser(userId);
            transformerSubstationEntity.setUpdateTime(new Date());
            sql.append("update czt_transformer_substation set id=:id,cts_name=:ctsName,position=:position,province=:province,city=:city,county=:county,longitude=:longitude,latitude=:latitude,type_substation=:typeSubstation,voltage_grade=:voltageGrade,structure_type=:structureType,fortification_intensity=:fortificationIntensity,substation_total_cost=:substationTotalCost,cost_high_voltage_outdoor=:costHighVoltageOutdoor,cost_indoor_equipment=:costIndoorEquipment,cost_building=:costBuilding,year=:year,site=:site,update_user=:updateUser,update_time=:updateTime,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,attach_id=:attachId");
            sql.append(" where cts_id = '"+transformerSubstationEntity.getCtsId()+"' ");
            SqlParameterSource source = new BeanPropertySqlParameterSource(transformerSubstationEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("8")){
            OverheadLineEntity overheadLineEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), OverheadLineEntity.class);
            overheadLineEntity.setUpdateUser(userId);
            overheadLineEntity.setUpdateTime(new Date());
            sql.append("update czt_overhead_line set id=:id,province=:province,city=:city,county=:county,col_name=:colName,fortification_intensity=:fortificationIntensity,voltage_grade35=:voltageGrade35,line_length35=:lineLength35,loop_length35=:loopLength35,landform35=:landform35,unit_cost_line35=:unitCostLine35,type35=:type35,number35=:number35,unit_cost_tower35=:unitCostTower35,voltage_grade66=:voltageGrade66,line_length66=:lineLength66,loop_length66=:loopLength66,landform66=:landform66,unit_cost_line66=:unitCostLine66,type66=:type66,number66=:number66,unit_cost_tower66=:unitCostTower66,voltage_grade110=:voltageGrade110,line_length110=:lineLength110,loop_length110=:loopLength110,landform110=:landform110,unit_cost_line110=:unitCostLine110,type110=:type110,number110=:number110,unit_cost_tower110=:unitCostTower110,voltage_grade220=:voltageGrade220,line_length220=:lineLength220,loop_length220=:loopLength220,landform220=:landform220,unit_cost_line220=:unitCostLine220,type220=:type220,number220=:number220,unit_cost_tower220=:unitCostTower220,voltage_grade330=:voltageGrade330,line_length330=:lineLength330,loop_length330=:loopLength330,landform330=:landform330,unit_cost_line330=:unitCostLine330,type330=:type330,number330=:number330,unit_cost_tower330=:unitCostTower330,voltage_grade500=:voltageGrade500,line_length500=:lineLength500,loop_length500=:loopLength500,landform500=:landform500,unit_cost_line500=:unitCostLine500,type500=:type500,number500=:number500,unit_cost_tower500=:unitCostTower500,update_user=:updateUser,update_time=:updateTime,del_flag=:delFlag,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,attach_id=:attachId");
            sql.append(" where col_id = '"+overheadLineEntity.getColId()+"'");
            SqlParameterSource source = new BeanPropertySqlParameterSource(overheadLineEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("9")){
            CableRouteEntity cableRouteEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), CableRouteEntity.class);
            cableRouteEntity.setUpdateUser(userId);
            cableRouteEntity.setUpdateTime(new Date());
            sql.append("update czt_cable_route set id=:id,province=:province,city=:city,county=:county,ccr_name=:ccrName,fortification_intensity=:fortificationIntensity,line_length=:lineLength,cost_line=:costLine,update_user=:updateUser,update_time=:updateTime,del_flag=:delFlag,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,attach_id=:attachId");
            sql.append(" where ccr_id = '"+cableRouteEntity.getCcrId()+"' ");
            SqlParameterSource source = new BeanPropertySqlParameterSource(cableRouteEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("10")){
            ImportantPowerhouseEntity importantPowerhouseEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), ImportantPowerhouseEntity.class);
            importantPowerhouseEntity.setUpdateUser(userId);
            importantPowerhouseEntity.setUpdateTime(new Date());
            sql.append("update czt_important_powerhouse set id=:id,cip_name=:cipName,province=:province,city=:city,county=:county,position=:position,longitude=:longitude,latitude=:latitude,year=:year,fortification_intensity=:fortificationIntensity,installed_capacity=:installedCapacity,generating_type=:generatingType,cost_power_plant=:costPowerPlant,cost_substation_equipment=:costSubstationEquipment,cost_generating_equipment=:costGeneratingEquipment,area_steel_structures=:areaSteelStructures,unit_cost_steel_structure=:unitCostSteelStructure,area_reinforced_concrete=:areaReinforcedConcrete,unit_cost_reinforced_concrete=:unitCostReinforcedConcrete,area_masonry_structure=:areaMasonryStructure,unit_costmasonry_structure=:unitCostmasonryStructure,update_user=:updateUser,update_time=:updateTime,del_flag=:delFlag,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,attach_id=:attachId");
            sql.append(" where cip_id = '"+importantPowerhouseEntity.getCipId()+"'");
            SqlParameterSource source = new BeanPropertySqlParameterSource(importantPowerhouseEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("11")){
            CommIndoorEquipmentEntity commIndoorEquipmentEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), CommIndoorEquipmentEntity.class);
            commIndoorEquipmentEntity.setUpdateUser(userId);
            commIndoorEquipmentEntity.setUpdateTime(new Date());
            sql.append("update czt_comm_indoor_equipment  set province=:province,city=:city,county=:county,in_object_name=:inObjectName,location=:location,object_lon=:objectLon,object_lat=:objectLat,device_type=:deviceType,device_name=:deviceName,model=:model,in_floor=:inFloor,fixed_form=:fixedForm,bolt_diameter=:boltDiameter,purchase_cost=:purchaseCost,manufacturers=:manufacturers,size=:size,weight=:weight,update_user=:updateUser,update_time=:updateTime,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,attach_id=:attachId");
            sql.append(" where ccie_id = '"+commIndoorEquipmentEntity.getCcieId()+"' ");
            SqlParameterSource source = new BeanPropertySqlParameterSource(commIndoorEquipmentEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("12")){
            TvTowerEntity tvTowerEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), TvTowerEntity.class);
            tvTowerEntity.setUpdateUser(userId);
            tvTowerEntity.setUpdateTime(new Date());
            sql.append("update czt_tv_tower set object_name=:objectName,location=:location,province=:province,city=:city,county=:county,object_lon=:objectLon,object_lat=:objectLat,ctt_type=:cttType,area=:area,year=:year,height=:height,tower_elevation=:towerElevation,bulding_site=:buldingSite,design_intensity=:designIntensity,field_type=:fieldType,status=:status,reconstruction_cost=:reconstructionCost,antenna_elevation=:antennaElevation,period=:period,colmn_type=:colmnType,base_type=:baseType,base_story_num=:baseStoryNum,base_height=:baseHeight,update_user=:updateUser,update_time=:updateTime,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,attach_id=:attachId");
            sql.append(" where ctt_id = '"+tvTowerEntity.getCttId()+"' ");
            SqlParameterSource source = new BeanPropertySqlParameterSource(tvTowerEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("13")){
            MajorProjectEntity majorProjectEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), MajorProjectEntity.class);
            majorProjectEntity.setUpdateUser(userId);
            majorProjectEntity.setUpdateTime(new Date());
            sql.append("update czt_major_project set earthquake_name=:earthquakeName,occurrence_time=:occurrenceTime,magnitude=:magnitude,project_type=:projectType,intensity=:intensity,year=:year,defense_situation=:defenseSituation,destructive_state=:destructiveState,attach_id=:attachId,update_user=:updateUser,update_time=:updateTime,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,province=:province,city=:city,county=:county");
            sql.append(" where cmp_id = '"+majorProjectEntity.getCmpId()+"' ");
            SqlParameterSource source = new BeanPropertySqlParameterSource(majorProjectEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }else if(type.equals("14")){
            RdInformationEntity rdInformationEntity = JSONObject.parseObject(JSONObject.toJSONString(map1.get(type)), RdInformationEntity.class);
            rdInformationEntity.setUpdateUser(userId);
            rdInformationEntity.setUpdateTime(new Date());
            sql.append("update czt_reservior set cr_name=:crName,location=:location,longitude=:longitude,latitude=:latitude,capacity=:capacity,year=:year,dam_length=:damLength,dam_height=:damHeight,top_width=:topWidth,structure_type=:structureType,type=:type,intensity=:intensity,site=:site,space=:space,filling=:filling,dam_foundation=:damFoundation,maintenance_status=:maintenanceStatus,update_user=:updateUser,update_time=:updateTime,extends1=:extends1,extends2=:extends2,extends3=:extends3,extends4=:extends4,extends5=:extends5,extends6=:extends6,extends7=:extends7,extends8=:extends8,extends9=:extends9,extends10=:extends10,province=:province,city=:city,county=:county,upload_time=:uploadTime");
            sql.append(" where cr_id = '"+rdInformationEntity.getCrId()+"' ");
            SqlParameterSource source = new BeanPropertySqlParameterSource(rdInformationEntity);
            return namedParameterJdbcTemplate.update(sql.toString(), source) > 0;
        }
        return null;
    }

    @Override
    public boolean delete(String id, String type) {
        //type 1:地下管网   2:水厂泵房  3:水厂水池  4:燃气-储气罐    5:桥梁    6:道路    7:变电站
        // 8:架空线路  9:电缆线路  10:发电厂  11:通信室内设备   12:电视塔
        String sql = "";
        if(type.equals("1")){
            sql = "update czt_dx_pipe_network set del_flag = 1  where cdpn_id = ?";
        }else if(type.equals("2")){
            sql = "update czt_waterworks set del_flag = 1  where cw_id = ?";
        }else if(type.equals("3")){
            sql = "update czt_pool set del_flag = 1  where cp_id = ?";
        }else if(type.equals("4")){
            sql = "update czt_air_receiver set del_flag = 1  where car_id = ?";
        }else if(type.equals("6")){
            sql = "update czt_road set del_flag = 1  where cr_id = ?";
        }else if(type.equals("7")){
            sql = "update czt_transformer_substation set del_flag = 1  where cts_id = ?";
        }else if(type.equals("8")){
            sql = "update czt_dx_pipe_network set del_flag = 1  where cb_id = ?";
        }else if(type.equals("9")){
            sql = "update czt_cable_route set del_flag = 1  where ccr_id = ?";
        }else if(type.equals("10")){
            sql = "update czt_important_powerhouse set del_flag = 1  where cip_id = ?";
        }else if(type.equals("11")){
            sql = "update czt_comm_indoor_equipment set del_flag = 1  where ccie_id = ?";
        }else if(type.equals("12")){
            sql = "update czt_tv_tower set del_flag = 1  where ctt_id = ?";
        }else if(type.equals("13")){
            sql = "update czt_major_project set del_flag = 1  where cmp_id = ?";
        }else if(type.equals("14")){
            sql = "update czt_reservior set del_flag = 1  where cr_id = ?";
        }
        return jdbcTemplate.update(sql,id) > 0;
    }

    @Override
    public boolean saveMajorProject(MajorProjectEntity majorProjectEntity) {
        String sql = "insert into czt_major_project values (:cmpId,:id,:earthquakeName,:occurrenceTime,:magnitude,:projectType,:intensity,:year," +
                ":defenseSituation,:destructiveState,:attachId,:createUser,:createTime,:updateUser,:updateTime,:delFlag,:extends1,:extends2," +
                ":extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10,:province,:city,:county)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(majorProjectEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public int getPipeNetworkDataByProvince(String province) {
        try{
            String sql="select count(cdpn_id) from czt_dx_pipe_network where del_flag= '0' and province= ?";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getWaterworksDataByProvince(String province) {
        try{
            String sql="select count(cw_id) from czt_waterworks where del_flag= '0' and province= ?";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getPoolDataByProvince(String province) {
        try{
            String sql="select count(cp_id) from czt_pool where del_flag= '0' and province= ?";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getAirReceiverDataByProvince(String province) {
        try{
            String sql="select count(car_id) from czt_air_receiver where del_flag= '0' and province= ?";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getBridgeDataByProvince(String province) {
        try{
         /*   String sql="select count(cb_id) from czt_bridge where del_flag= '0' and province= ?";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
*/
            StringBuilder bridgeSql = new StringBuilder("select * from czt_bridge_point where del_flag = '0' and province='"+province+"' union select * from czt_bridge_line  where del_flag = '0' and province='"+province+"'");
            Integer count = jdbcTemplate.query(bridgeSql.toString(), new BeanPropertyRowMapper<>(Object.class)).size();
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getRoadDataByProvince(String province) {
        try{
            String sql="select count(cr_id) from czt_road where del_flag= '0' and province= ?";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getTransformerSubstationDataByProvince(String province) {
        try{
            String sql="select count(cts_id) from czt_transformer_substation where del_flag= '0' and province= ?";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getOverheadLineDataByProvince(String province) {
        try{
            String sql="select count(col_id) from czt_overhead_line where del_flag= '0' and province= ?";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getCableRouteDataByProvince(String province) {
        try{
            String sql="select count(ccr_id) from czt_cable_route where del_flag= '0' and province= ? ";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getImportantPowerhouseDataByProvince(String province) {
        try{
            String sql="select count(cip_id) from czt_important_powerhouse where del_flag= '0' and province= ? ";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getCommIndoorEquipmentDataByProvince(String province) {
        try{
            String sql="select count(ccie_id) from czt_comm_indoor_equipment where del_flag= '0' and province= ?";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getTvTowerDataByProvince(String province) {
        try{
            String sql="select count(ctt_id) from czt_tv_tower where del_flag= '0' and province= ? ";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public Map bridgeFindById(String id, String flag) {
        StringBuilder sql = new StringBuilder();
        if(flag.equals("0")){
            sql.append("select * from czt_bridge_point where del_flag = '0' and cb_id = ?");
        }else {
            sql.append("select * from czt_bridge_line where del_flag = '0' and cb_id = ?");
        }
        BridgeEntity bridgeEntity = jdbcTemplate.queryForObject(sql.toString(), new BeanPropertyRowMapper<>(BridgeEntity.class),id);
        Map<String, Object> map = new HashMap<>();
        map.put("data",bridgeEntity);
        return map;
    }

    @Override
    public boolean bridgeDelete(String id, String flag) {
        StringBuilder sql = new StringBuilder();
        if(flag.equals("0")){
            sql.append("update czt_bridge_point set del_flag = 1  where cb_id = ?");
        }else {
            sql.append("update czt_bridge_line set del_flag = 1  where cb_id = ?");
        }
        return jdbcTemplate.update(sql.toString(),id) > 0;
    }

    @Override
    public String getCode(Integer type) {
        try {
            StringBuilder sql = new StringBuilder("select version_code from czt_smx_version where del_flag = '0' and type = "+type+" order by create_time desc limit 1");
            return jdbcTemplate.queryForObject(sql.toString(), String.class);
        } catch (DataAccessException e) {
            return null;
        }
    }

    @Override
    public List<SmxVersionEntity> getByRegionAndUserAndType(RegionParam param, String userId,String fileName) {
        try {
            Integer type = param.getType();
            String province = param.getProvince();
            String city = param.getCity();
            String county = param.getCounty();
            String sql = "select * from czt_smx_version where province = '"+province+"' and city = '"+city+"' and county = '"+county+"' and create_user = '"+userId+"' and type = "+type+" and file_name = '"+fileName+"'";
            return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SmxVersionEntity.class));
        } catch (DataAccessException e) {
            return null;
        }
    }

    @Override
    public void deleteOldVersionData(String versionId, Integer type) {
        StringBuilder sql = new StringBuilder("update ");
        switch (type){
            case 1:
                sql.append("");
                break;
            case 2:
                sql.append("");
                break;
            case 3:
                sql.append("");
                break;
            case 4:
                sql.append("");
                break;
            case 5:
                sql.append("");
                break;
            case 6:
                sql.append("czt_smx_road ");
                break;
            case 7:
                sql.append("");
                break;
            case 8:
                sql.append("");
                break;
            case 9:
                sql.append("");
                break;
            case 10:
                sql.append("");
        }
        StringBuilder sb = new StringBuilder("set del_flag = '1' where version_id = '" + versionId + "'");
        jdbcTemplate.update(sql.append(sb).toString());
    }
}
